package com.zhengdongzulin.zuke.app.main.home

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.Banner
import com.zhengdongzulin.zuke.app.data.City
import com.zhengdongzulin.zuke.app.data.HomeItem
import com.zhengdongzulin.zuke.app.data.HotRoom
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class HomeVm : BaseViewModel() {

    var get_city_com_list: StateLiveData<MutableList<City>> = StateLiveData()

    fun get_city_com_list() {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_CITY_COM_LIST)
                            .toResponse<MutableList<City>>()
                            .await()
                    get_city_com_list.postValueAndSuccess(r)
                }, {
            assignment(it, get_city_com_list)
        }
        )
    }

    var get_banner_pic_list: StateLiveData<MutableList<Banner>> = StateLiveData()

    /**
     * picStatus	否	string	状态（0，禁用；1，启用）
     */
    fun get_banner_pic_list(cityId: String?, picStatus: String = "1") {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_BANNER_PIC_LIST)
                            .add("cityId", cityId)
                            .add("wechatId", mShareViewModel!!.apartmentTypeId.value!!)
                            .add("picStatus", picStatus)
                            .toResponse<MutableList<Banner>>()
                            .await()
                    get_banner_pic_list.postValueAndSuccess(r)
                }, {
            assignment(it, get_banner_pic_list)
        }
        )
    }

    var get_house_item_list: StateLiveData<MutableList<HomeItem>> = StateLiveData()

    /**
     * marketing	是	Integer	是否为推介门店 0是 1不是
     */
    fun get_house_item_list(cityId: String?, marketing: String = "0") {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_HOUSE_ITEM_LIST)
                            .add("cityId", cityId)
                            .add("wechatId", mShareViewModel!!.apartmentTypeId.value!!)
                            .add("marketing", marketing)
                            .toResponse<MutableList<HomeItem>>()
                            .await()
                    get_house_item_list.postValueAndSuccess(r)
                }, {
            assignment(it, get_house_item_list)
        }
        )
    }

    var get_hot_house_list: StateLiveData<MutableList<HotRoom>> = StateLiveData()

    /**
     * isHot	是	String	是否为推荐的热门房间 1热门 0非热门
     */
    fun get_hot_house_list(cityId: String?, isHot: String = "1") {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_HOT_HOUSE_LIST)
                            .add("cityId", cityId)
                            .add("wechatId", mShareViewModel!!.apartmentTypeId.value!!)
                            .add("isHot", isHot)
                            .toResponse<MutableList<HotRoom>>()
                            .await()
                    get_hot_house_list.postValueAndSuccess(r)
                }, {
            assignment(it, get_hot_house_list)
        }
        )
    }


}